﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel.Description;
using System.Collections.ObjectModel;

namespace WcfContrib.Metadata
{
    /// <summary>
    /// Represents a set of policy definitions set defined on the endpoint elements
    /// </summary>
    public sealed class EndpointPolicyDefinitionSet
    {
        /// <summary>
        /// Gets the policies defined on the binding
        /// </summary>
        public PolicyAssertionCollection Binding { get; internal set; }

        /// <summary>
        /// Gets the policies defined on the operations
        /// </summary>
        public Collection<OperationPolicyDescription> Operations { get; internal set; }

        /// <summary>
        /// Gets the policies defined on a specific operation description
        /// </summary>
        /// <param name="operation">The operation description</param>
        /// <returns></returns>
        public OperationPolicyDescription GetOperationPolicies(OperationDescription operation)
        {
            OperationPolicyDescription desc = null;

            foreach (var item in Operations)
            {
                if (item.Description.Equals(operation))
                {
                    desc = item;

                    break;
                }
            }

            return desc;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EndpointPolicyDefinitionSet"/> class.
        /// </summary>
        public EndpointPolicyDefinitionSet()
        {
            Binding = new PolicyAssertionCollection();

            Operations = new Collection<OperationPolicyDescription>();
        }
    }
}
